package com.bocloud.cmp.dao.app.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.bocloud.cmp.dao.app.ApplicationLayoutInfoDao;
import com.bocloud.cmp.entity.app.resource.ApplicationLayoutInfo;
import com.bocloud.common.utils.MapTools;
import com.bocloud.database.core.BasicDao;

/**
 * 
 * @author zjm
 * @date 2017年3月18日
 */
@Repository
public class ApplicationLayoutInfoDaoImpl extends BasicDao implements ApplicationLayoutInfoDao{

	@Override
	public boolean saveApplicationLayoutInfo(ApplicationLayoutInfo applicationLayoutInfo) throws Exception {
		return this.baseSaveEntity(applicationLayoutInfo);
	}

	@Override
	public boolean deleteApplicationLayoutInfo(ApplicationLayoutInfo applicationLayoutInfo) throws Exception {
		return this.baseDelete(applicationLayoutInfo);
	}

	@Override
	public ApplicationLayoutInfo getByAppIdAndLayoutId(Long appId, Long layoutId) throws Exception {
		String sql = "select * from application_layout_info where "
				+ "application_id = :appId and layout_id = :layoutId";
		Map<String, Object> params = MapTools.simpleMap("appId", appId);
		params.put("layoutId", layoutId);
		List<Object> list = this.queryForList(sql, params, ApplicationLayoutInfo.class);
		List<ApplicationLayoutInfo> result = new ArrayList<>();
		for (Object object : list) {
			result.add((ApplicationLayoutInfo) object);
		}
		if (list.isEmpty()) {
			return null;
		}
		return result.get(0);
	}
}
